/*
 *  MSMLocator.cpp
 *  libavid
 *
 *  Created by Peter on 25.02.12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include "MSMLocator.h"
#include "AStream.h"

A_IMPLEMENT_CLASS( 'MSML', MSMLocator, AObject );

void MSMLocator::readFromStream( AStream& str, const AObjDoc& objd )
{
	UInt8 tagMark, version;
	str.readPod( tagMark );
	str.readPod( version );
	TR_ASSERT( tagMark == 0x02 );
	TR_ASSERT( version == 0x02 );
	
	str.readPod( _mobIdHigh );
	str.readPod( _mobIdLow );
	_lastKnownVolume = str.readString();
	
	// PClass Ext DomainType
	str.readPod( tagMark );
	str.readPod( version );
	TR_ASSERT( tagMark == 0x01 );
	TR_ASSERT( tagMark == 0x01 );
	str.readPod( tagMark ),
	TR_ASSERT( tagMark == 71 );
	str.readPod( _domainType );
	
	// PClass Ext MobID. Function handles all the tag marks and versions for us.
	readMobIdFromAObjDocStream( str, _mobId );
	
	// End TagMark
	str.readPod( tagMark );
	TR_ASSERT( tagMark == 0x03 );
}

#define TRACE_FIELD( x ) "\t" #x ": " << x << std::endl

void MSMLocator::dump( std::ostream& str ) const
{
	str << "MSMLocator {" << std::endl;
	
	str << TRACE_FIELD( _mobIdHigh );
	str << TRACE_FIELD( _mobIdLow );
	str << TRACE_FIELD( _lastKnownVolume );
	str << TRACE_FIELD( _domainType );
	str << TRACE_FIELD( _mobId );
	
	str << "}" << std::endl;
}